package com.edu.edumanager.controller;


import com.edu.edumanager.service.CourseService;
import com.edu.edumanager.vo.EduCourseInfo;
import com.edu.edumanager.vo.EduCourseVo;
import com.edu.edumanager.vo.EduResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @program: edu-manager
 * @description:
 * @author: Jaime
 * @create: 2021-08-18 14:12
 **/
@RestController
@RequestMapping("/eduservice/course")
@CrossOrigin
public class EduCourseController {
    @Autowired
    private CourseService courseService;

    /**
     * 添加couse和des
     * @param
     * @return 结果集
     */
    @RequestMapping("/addCourseInfo")
    public EduResult addCourseInfo(@Valid @RequestBody EduCourseInfo courseInfo) {
        int id = courseService.addCourse(courseInfo);
        return EduResult.ok().data("courseId",id);
    }

    /**
     * 根据id查course des
     * @param courseId
     * @return
     */
    @RequestMapping("/getCourseAndDes/{courseId}")
    public  EduResult findCourseInfoById(@PathVariable Integer courseId){
        EduCourseInfo courseInfo = courseService.findCourseInfoById(courseId);
        return EduResult.ok().data("courseInfo",courseInfo);
    };

    /**
     * 添加couse和des
     * @param
     * @return 结果集
     */
    @RequestMapping("/updateCourseInfo")
    public EduResult updateCourseInfo(@Valid @RequestBody EduCourseInfo courseInfo) {
        System.out.println(courseInfo);
         int id = courseService.updateCourseInfo(courseInfo);
        return EduResult.ok().data("courseId",id);
    }

    /**
     * 得到couse对象 回显信息
     * @param courseId
     * @return
     */
    @RequestMapping("/getCourseTeacher/{courseId}")
    public EduResult getCourseTeacher(@PathVariable Integer courseId){
        EduCourseVo course = courseService.getCourseTeacher(courseId);
        return EduResult.ok().data("course",course);
    };

    /**
     * couse 发布课程
     * @param courseId
     * @return
     */
    @RequestMapping("/publishCourse/{courseId}")
    public EduResult publishCourse(@PathVariable Integer courseId){
        int count = courseService.publishCourse(courseId);
        return EduResult.ok().data("count",count);
    }

    /**
     * 分页查询course数据
     * @param currentPage
     * @param limit
     * @return
     */
    @RequestMapping("/conditionsQuery/{currentPage}/{limit}")
    public EduResult conditionsQuery(@PathVariable Integer currentPage, @PathVariable Integer limit) {
        EduResult result = courseService.conditionsQuery(currentPage,limit);
        return result;
    }
    @RequestMapping("/deleteCourse/{courseId}")
    public EduResult deleteCourse(@PathVariable Integer courseId){
        int count = courseService.deleteCourse(courseId);
        return EduResult.ok().data("count",count);
    }
}
